<?php

class Core_Widget
{
	static $_instance = null;

	public function getConfigs()
	{
		return new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
	}

	public static function getInstance()
	{
			if (null === self::$_instance) {
					self::$_instance = new self();
			}
			return self::$_instance;
	}

	public static function getWidget($path)
	{
		$file 		= self::getInstance()->getPath($path).array_pop(explode('/',$path)).'.php';
		$class 		= ucfirst(str_replace('/', '_', $path));
		if(is_file($file))
		{
			require_once($file);
			if(class_exists($class))
				return new $class($path);
		}
		return new Core_Widget_Empty;
	}

	public function getPath($path)
	{
		$moduleDirectory = self::getInstance()->getConfigs()->resources->frontController->moduleDirectory;
		return empty($moduleDirectory)?'':(rtrim($moduleDirectory, '/').'/').rtrim($path, '/').'/';
	}
}